/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import net.sf.appia.core.AppiaEventException;
import net.sf.appia.core.Channel;
import net.sf.appia.core.Event;
import net.sf.appia.core.Layer;
import net.sf.appia.core.Session;
import net.sf.appia.core.events.channel.ChannelInit;
import util.Debug;

/**
 *
 * @author Welington
 */
public abstract class CustomSession extends Session{
    protected Class current;
    protected Debug debug;
    
    public CustomSession(Layer layer) {
        super(layer);
        debug = Debug.getInstance();
        current = CustomSession.class;
    }
    
    protected abstract void handleInit(ChannelInit event);
    
    protected void sendEvent(Event event) {
        debug.print(Debug.LOG, current, "sendEvent(Event event)");
        try {
            event.go();
        } catch (AppiaEventException e) {
            debug.print(Debug.ERROR, current, e.getLocalizedMessage());
        }
    }
    
    protected void sendAsyncEvent(Event event, Channel channel, int dir) {
        debug.print(Debug.LOG, current, "sendAsyncEvent(Event event, Channel channel, int dir)");
        try {
            event.asyncGo(channel, dir);
        } catch (AppiaEventException e) {
            debug.print(Debug.ERROR, current, e.getLocalizedMessage());
        }
    }
    
    protected void initEvent(Event event) {
        try {
            event.init();
        } catch (AppiaEventException e) {
            debug.print(Debug.ERROR, current, e.getLocalizedMessage());
        }
    }
}
